<?php

!defined('IN_SYSTEM') && exit('Access denied');

class class_view {
    private $_tplvars = array();
    private $_scripts = array();
    private static $stance = null;
    
    private function __construct() {
        //todo
    }
    public static function getInstance() {
        if (is_null(self::$stance)) {
            $c = __CLASS__;
            self::$stance = new $c();
        }
        return self::$stance;
    }

    public function __get($key){
        return $this->_tplvars[$key];
    }
    public function __set($key,$val) {
        $this->_tplvars[$key] = $val;
    }

    public function addScript($script_list) {
        if (!empty($script_list)) {
            $this->_scripts = array_merge($this->_scripts,explode(',',$script_list));
        }
    }
    public function listScript() {
        if (!empty($this->_scripts)) {
            $html = '';
            foreach ($this->_scripts as $script) {
                $html .= "<script type='text/javascript' src='./res/script/{$script}.js'></script>";
            }
            echo $html;
        }
    }

    public function render($tpl_file) {
        include __PATH__."/source/template/{$tpl_file}.htm";
    }

    public function _debug() {
        var_dump($this->_tplvars);
    }
}